package leetcode.code0456;

import java.util.Stack;

import leetcode.IDebug;

public class Solution implements IDebug {

	public boolean find132pattern(int[] nums) {
		Stack<Integer> stack = new Stack<>();
		int len = nums.length;
		int[] mins = new int[len];
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < len; i++) {
			int cur = nums[i];
			while (!stack.isEmpty() && nums[stack.peek()] <= cur) {
				stack.pop();
			}
			if (!stack.isEmpty() && cur > mins[stack.peek()]) {
				return true;
			}
			min = Math.min(min, cur);
			mins[i] = min;
			stack.add(i);
		}
		return false;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
